//
//  BaseColumnModel.m
//  BaseFramework01
//
//  Created by IMAC on 2017/6/2.
//  Copyright © 2017年 IMAC. All rights reserved.
//

#import "BaseColumnModel.h"

@implementation BaseColumnModel

- (instancetype)initWithDict:(NSDictionary *)dict{
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
    
}

-(id)valueForUndefinedKey:(NSString *)key{
    NSLog(@"出现异常，该key不存在%@",key);
    return nil;
}

+(void)requestForHomeColumnListDataWithResult:(success)success failure:(failure)failure {
    
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"testForHomeColumnList.json" withExtension:nil ];
    NSDictionary *dict  =  [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL: url ] options:NSJSONReadingAllowFragments error:nil];
    if (dict) {
        NSArray *dataArray = dict[@"data"][@"columnInfos"];
        NSMutableArray *arrm = [NSMutableArray arrayWithCapacity:dataArray.count];
        for (NSDictionary *modelDict in dataArray) {
            BaseColumnModel *model = [[BaseColumnModel alloc]initWithDict:modelDict];
            [arrm addObject:model];
        }
        if (success) {
            success(arrm);
        }
        
    }else{
        if (failure) {
             failure();
        }
       
        
    }
 
}
@end
